<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getData()">
      <el-button type="primary" @click="addOrUpdateHandle()">修改</el-button>
    </el-form>

    <el-form :model="dataForm" label-width="140px">
      <el-form-item label="店铺名称:">
        <!-- <el-input v-model="data.storeName"></el-input> -->
        <label>{{data.storeName}}</label>
      </el-form-item>
      <el-form-item label="店主:">
        <label>{{data.storekeeperId}}=============================【要修改】</label>
      </el-form-item>
      <el-form-item label="所属分类:">
        <label>{{data.classifyId}}=============================【要修改】</label>
      </el-form-item>
      <el-form-item label="店铺描述:">
        <label>{{data.storeDesc}}</label>
      </el-form-item>
      <el-form-item label="店铺公告:">
        <label>{{data.storeAnno}}</label>
      </el-form-item>
      <el-form-item label="店铺头像:">
        <img :src="data.storeIcon" />
      </el-form-item>
      <el-form-item label="店铺背景图:">
        <img :src="data.backgroundUrl" />
      </el-form-item>
      <el-form-item label="店铺所在区域:">
        <label>{{data.storeLocation}}</label>
      </el-form-item>
      <el-form-item label="店铺详细地址:">
        <label>{{data.storeAddress}}</label>
      </el-form-item>
      <el-form-item label="店铺联系方式:">
        <label>{{data.storePhone}}</label>
      </el-form-item>
      <el-form-item label="店铺状态:">
        <i class="el-icon-time"></i>
        <el-switch
          v-model="data.storeStatus"
          active-color="#13ce66"
          inactive-color="#ff4949"
          :active-value="1"
          :inactive-value="0"
          @change="updateBrandStatus(data)"
        ></el-switch>
      </el-form-item>
      <el-form-item label="店铺诚信度:">
        <label>{{data.storeIntegrity}}</label>
      </el-form-item>
      <el-form-item label="营业许可证:">
        <img :src="data.businessLicense" />
      </el-form-item>
      <el-form-item label="店铺招牌图:">
        <img :src="data.storeSign" />
      </el-form-item>
      <el-form-item label="店铺装潢图:">
        <img :src="data.storeFront" />
      </el-form-item>
    </el-form>

    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from "./store-add-or-update";
export default {
  data() {
    return {
      dataForm: {
        key: "",
      },
      data: [],
      status: 1,
      dataLoading: false,
      addOrUpdateVisible: false,
    };
  },
  components: {
    AddOrUpdate,
  },
  activated() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataLoading = true;
      this.$http({
        url: this.$http.adornUrl("/store/store/info/1"),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          key: this.dataForm.key,
        }),
      }).then(({ data }) => {
        this.data = data.store;
        this.dataLoading = false;
        console.log(this.data);
      });
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(this.data.storeId);
      });
    },
    updateBrandStatus(data) {
      console.log("最新状态", data);
      let { storeId, storeStatus } = data;
      //发送请求，修改状态
      this.$http({
        url: this.$http.adornUrl("/store/store/update"),
        method: "post",
        data: this.$http.adornData({ storeId, storeStatus }, false),
      }).then(({ data }) => {
        this.$message({
          type: "success",
          message: "状态更新成功",
        });
      });
    },
  },
};
</script>
